import { CommonEntity } from '../../../../common/entities/common.entity';
import { Menu } from '../../menu/entities/menu.entity';
import { Permission } from '../../permission/entities/permission.entity';
import { Column, Entity, JoinTable, ManyToMany } from 'typeorm';

@Entity({
  name: 'sys_role',
  comment: '系统角色表',
})
export class Role extends CommonEntity {
  @Column({
    length: 50,
    collation: 'utf8mb4_bin',
    type: 'varchar',
    comment: '名称',
  })
  name: string;

  @Column({
    length: 50,
    type: 'varchar',
    collation: 'utf8mb4_bin',
    nullable: true,
    comment: '角色值(初始化超级管理员角色标识)',
  })
  value: string;

  @Column({
    length: 100,
    type: 'varchar',
    default: null,
    comment: '备注',
  })
  remark: string;

  @Column({
    default: true,
    comment: '状态',
  })
  state: boolean;

  @ManyToMany(() => Menu, {
    createForeignKeyConstraints: false,
  })
  @JoinTable({
    name: 'ref_sys_role_sys_menu',
    joinColumn: {
      name: 'sys_role_id',
    },
    inverseJoinColumn: {
      name: 'sys_menu_id',
    },
  })
  menus?: Menu[];

  @ManyToMany(() => Permission, {
    createForeignKeyConstraints: false,
  })
  @JoinTable({
    name: 'ref_sys_role_sys_permission',
    joinColumn: {
      name: 'sys_role_id',
    },
    inverseJoinColumn: {
      name: 'sys_permission_id',
    },
  })
  permissions?: Permission[];
}
